package com.zx.learn.flink.utils;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @desc: 从test-topic主题中消费数据
 */
public class KafkaConsumer {

    public static void main(String[] args) throws Exception {

        // 包括但不限于kafka的消费者id
        String application = "KafkaConsumer";

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
        ModelUtil.deployRocksdbCheckpoint(env, application, 3 * 1000);
        ModelUtil.deployRestartStrategy(env);

        env
                .addSource(KafkaUtil.getKafkaConsumerAvro("test-topic", application, String.class))
                .map(new MapFunction<String, String>() {
                    @Override
                    public String map(String value) throws Exception {
                        System.out.println(value);
                        return value;
                    }
                });
        env.execute(application);
    }
}
